package com.carpedil.smvc.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.carpedil.smvc.po.Permissions;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/** @author Administrator */
@Repository
public interface PermissionsMapper extends BaseMapper<Permissions> {
  @Select(
      "select DISTINCT p.* "
          + "FROM user_role ur "
          + " INNER JOIN users u on u.id = ur.fk_user_id "
          + " INNER JOIN roles r on r.pk_id = ur.fk_role_id "
          + " INNER JOIN role_permission rp on rp.fk_role_id = r.pk_id "
          + " INNER JOIN permissions p on p.permission_pk_id = rp.fk_permission_id "
          + " WHERE u.user_name =#{userName}")
  @ResultMap("com.carpedil.smvc.dao.PermissionsMapper.permissionMap")
  List<Permissions> finPermissionsByUser(String userName);
}
